package com.example.util;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;


import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class StringUtils extends org.apache.commons.lang3.StringUtils {

    public static String toSqlName(String str) {

        Pattern p = Pattern.compile("[A-Z]");
        if (str == null || str.equals("")) {
            return "";
        }
        StringBuilder builder = new StringBuilder(str);
        Matcher mc = p.matcher(str);
        int i = 0;
        while (mc.find()) {
            builder.replace(mc.start() + i, mc.end() + i, "_" + mc.group().toLowerCase());
            i++;
        }
        if ('_' == builder.charAt(0)) {
            builder.deleteCharAt(0);
        }
        return builder.toString();
    }

    /**
     * 格式化array
     *
     * @param obj
     * @return
     */
    public static String[] toStringArray(String obj) {

        String[] stringArray = null;
        JSONArray jsonArray = JSON.parseArray(obj);
        stringArray = (String[]) jsonArray.toArray(new String[jsonArray.size()]);
        return stringArray;
    }

    /**
     * 隐藏 手机号中间
     *
     * @param mobile
     * @return
     * @Package: com.xg.util
     * @author: zzm
     * @date: 2017年6月22日 上午9:15:39
     */
    public static String decryptMoblie(String mobile) {

        String decryptmobile = "";
        if (StringUtils.isNotEmpty(mobile)) {
            String regex = "(\\d{3})(\\d+)(\\d{4})";
            decryptmobile = mobile.replaceAll(regex, "$1****$3");
        }
        return decryptmobile;
    }






}
